package com.motherchild.admin.controller;

import com.motherchild.admin.dto.EmployeeDTO;
import com.motherchild.admin.service.EmployeeService;
import com.motherchild.common.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employees")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/getList")
    public ApiResponse<List<EmployeeDTO>> getAllEmployees() {
        List<EmployeeDTO> employees = employeeService.getAllEmployees();
        return ApiResponse.success(employees);
    }

    @PostMapping("/addEmployee")
    public ApiResponse<Void> addEmployee(@RequestBody EmployeeDTO employeeDTO) {
        employeeService.addEmployee(employeeDTO);
        return ApiResponse.success();
    }

    @PostMapping("/searchEmployee")
    public ApiResponse<List<EmployeeDTO>> searchEmployee(@RequestBody EmployeeDTO employeeDTO) {
        List<EmployeeDTO> employees = employeeService.searchEmployee(employeeDTO);
        return ApiResponse.success(employees);
    }

    @PutMapping("/updateEmployee/{id}")
    public ApiResponse<Void> updateEmployee(@PathVariable Long id, @RequestBody EmployeeDTO employeeDTO) {
        employeeDTO.setId(id);
        employeeService.updateEmployee(employeeDTO);
        return ApiResponse.success();
    }

    @DeleteMapping("/deleteEmployee/{id}")
    public ApiResponse<Void> deleteEmployee(@PathVariable Long id) {
        employeeService.deleteEmployee(id);
        return ApiResponse.success();
    }

} 